package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import bean.PopCarBrandBean;
import zhang.automobileservice.R;

/**
 * Created by Administrator on 2016/8/8.
 */
public class PopCarBrandAdapter extends RecyclerView.Adapter <PopCarBrandAdapter.MyViewHolder>{
    private Context context;
    private ArrayList<PopCarBrandBean> arrayList;

    public PopCarBrandAdapter(Context context, ArrayList<PopCarBrandBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.pop_car_brand_item,null);
        MyViewHolder viewHolder =  new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        PopCarBrandBean popCarBrandBean = arrayList.get(position);
        holder.tv_carName.setText(popCarBrandBean.getCarName());
        holder.iv_carBrand.setImageResource(popCarBrandBean.getCarBrand());
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tv_carName;
        ImageView iv_carBrand;
        public MyViewHolder(final View itemView) {
            super(itemView);
            tv_carName = (TextView) itemView.findViewById(R.id.tv_carName);
            iv_carBrand = (ImageView)itemView.findViewById(R.id.iv_carBrand);
        }
    }
}
